<?php
class Bootstrap{

	function __construct(){
		$url=addslashes(@$_GET['url']);
		$url=rtrim($url,'/');
		$url=explode('/',$url);

		$file=CONTROLLER.$url[0].'.php';
		$files=VIEW.$url[0].'.php';
		$view=new View();
		if(empty($url[0]))
		{
			if(!file_exists(CONTROLLER.'index.php'))
			{
				$error_name='index.php';
				$folder=CONTROLLER;
			  	include(PUBLICS.'errors.php');
			  	die();
			}
			else
			{
			  	require CONTROLLER.'index.php';
				$controller=new Index();
				$controller->index();
				return false;
				$controller->index();
			}
		}
		elseif(file_exists($file))
		{
                    #echo $file;exit;
			require $file;	
                        #echo '<pre>';print_R($url);exit;
			$controller = new $url[0];
			$controller->index();
		}
		elseif(file_exists($files))
		{
				$view->render($url[0]);
		}
		else
		{
			$sql=new sql();
			$sql->connect();
			$permalinks=explode('/',$_SERVER['REQUEST_URI']);
			$permalinks=$permalinks[count($permalinks)-1];
			
			$check=$sql->check("page",array("permalink"=>$permalinks));
			if($check){
				require CONTROLLER."p.php";	
				$controller = new P;
				$controller->index();
			  }else{
			$view->render("404");
			}
				
		}
	}
}

?>